﻿CREATE TABLE [dbo].[Folder]
(
	[Id] BIGINT NOT NULL IDENTITY(1,1) PRIMARY KEY,
	[UserId] BIGINT NOT NULL,
	[ParentFolderId] BIGINT NOT NULL,
	[IsPrivate] BIT NOT NULL,
	[IsParentFolderPrivate] BIT NOT NULL DEFAULT(0),
	[Name]	NVARCHAR(255) NOT NULL,
	CONSTRAINT [FK_Folder_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id]) ON DELETE NO ACTION ON UPDATE NO ACTION,
	CONSTRAINT [FK_Folder_Folder] FOREIGN KEY ([ParentFolderId]) REFERENCES [dbo].[Folder] ([Id]) ON DELETE NO ACTION ON UPDATE NO ACTION,
	CONSTRAINT [UQ_Folder_Name] UNIQUE ([UserId], [ParentFolderId], [Name])
)
